package org.ovirt.microvirt.services.events.impl;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import org.ovirt.microvirt.beans.events.Event;
import org.ovirt.microvirt.services.events.EventProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EventListener implements MessageListener {

	public EventListener(final EventProcessor eventProcessor) {
		super();
		this.eventProcessor = eventProcessor;
	}

	final EventProcessor eventProcessor;
	private final static Logger logger = LoggerFactory.getLogger(EventListener.class);

	@Override
	public void onMessage(final Message message) {
		ObjectMessage objMsg = (ObjectMessage) message;
		try {
			eventProcessor.process((Event) objMsg.getObject());
		} catch (JMSException e) {
			logger.info(e.getMessage(), e);
		}
	}

}
